package com.edu.common.util.xml;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

/**
 * @FileName：XmlUtil.java
 * @Description：@TODO
 * @Author：thy
 * @CreateTime：下午4:57:09
 */
public class XmlUtil {

	public static Element getRootElement(String xml) {
		try {
			DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
			DocumentBuilder db = dbf.newDocumentBuilder();
			InputSource is = new InputSource();
			is.setCharacterStream(new StringReader(xml));
			Document doc = db.parse(is);
			return doc.getDocumentElement();
		} catch (Exception e) {
			return null;
		}
	}


	public static String getValueAt(Element ele, String id) {
		
		try{
		
			return ele.getElementsByTagName(id).item(0).getFirstChild().getNodeValue();
		
		}catch(Exception e){
			return "";
		}
	}

}
